﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WaitUserControl.xaml.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Defines the WaitUserControl type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.Silverlight.UserControls
{
    using System.Windows;

    /// <summary>
    /// Defines the WaitUserControl type.
    /// </summary>
    public partial class WaitUserControl
    {
        /// <summary>
        /// Moving dependency property
        /// </summary>
        public static readonly DependencyProperty MovingProperty =
            DependencyProperty.Register("IsMoving", typeof(bool), typeof(WaitUserControl), new PropertyMetadata(DirtyChanged));

        /// <summary>
        /// Initializes a new instance of the <see cref="WaitUserControl"/> class.
        /// </summary>
        public WaitUserControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is moving.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is moving; otherwise, <c>false</c>.
        /// </value>
        public bool IsMoving
        {
            get
            {
                return (bool)GetValue(MovingProperty);
            }

            set
            {
                SetValue(MovingProperty, value);
            }
        }

        /// <summary>
        /// Fired when the value of the Dirty property changes
        /// </summary>
        /// <param name="obj">The object</param>
        /// <param name="eventArgs">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void DirtyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs)
        {
            var myself = obj as WaitUserControl;
            if (myself != null)
            {
                myself.WaitImage.Visibility = (bool)eventArgs.NewValue ? Visibility.Visible : Visibility.Collapsed;
            }
        }
    }
}
